<style scoped lang='less'>
    .car-private-page {
        .ivu-form {
            width: 100% !important;
        }
        .demo-upload-list {
            display: inline-block;
            width: 60px;
            height: 60px;
            text-align: center;
            line-height: 60px;
            border: 1px solid transparent;
            border-radius: 4px;
            overflow: hidden;
            background: #fff;
            position: relative;
            box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
            margin-right: 4px;
        }

        .demo-upload-list img {
            width: 100%;
            height: 100%;
        }

        .demo-upload-list-cover {
            display: none;
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            background: rgba(0, 0, 0, .6);
        }

        .demo-upload-list:hover .demo-upload-list-cover {
            display: block;
        }

        .demo-upload-list-cover i {
            color: #fff;
            font-size: 20px;
            cursor: pointer;
            margin: 0 2px;
        }

        .selected-search {
            border: 1px solid #dddee1;
            height: 200px;
            width: 260px;
            position: relative;
            border-radius: 4px;
        }

        .selected-search .search-action {
            position: absolute;
            top: 10px;
            left: 10px;
            right: 10px;
        }

        .selected-search .selected-arr {
            position: absolute;
            top: 50px;
            left: 20px;
            right: 20px;
            bottom: 10px;
            overflow: scroll;
        }

        .select-click {
            border: 1px solid #dddee1;
            border-radius: 4px;
            padding: 0 10px;
            margin-bottom: 10px;
        }

        .selected-search .selected-arr .selected-item {
            /*border-bottom: 1px solid #dfdfdf;*/
        }
        .driver-block1 {
            border: 15px solid rgb(240, 240, 240);
            /*padding: 30px;*/
            margin-left: 100px;
            margin-top: 20px;
            border-radius: 4px;
        }
    }


</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100" style="width: 100%">
        <div class="car-private-page" style="display: flex">
            <div class="driver-block1">
                <p style="color: white;font-size: 15px;font-weight: bold;text-align: center;padding: 10px 0;background: #2196F3;">车辆信息</p>
                <div style="padding:30px">
                    <Form-item label="车牌号" prop="platenum">
                        <i-input v-model="formValidate.platenum" placeholder="请输入车牌号"></i-input>
                    </Form-item>
                    <Form-item label="车辆卡编号" prop="cardid">
                        <i-input v-model="formValidate.cardid" placeholder="请输入车辆卡编号"></i-input>
                    </Form-item>
                    <Form-item label="车辆自编号" prop="carcode">
                        <i-input v-model="formValidate.carcode" placeholder="请输入车辆自编号"></i-input>
                    </Form-item>
                    <Form-item label="车辆车架号" prop="carsn">
                        <i-input v-model="formValidate.carsn" placeholder="请输入车辆车架号"></i-input>
                    </Form-item>
                    <Form-item label="车身颜色" prop="color">
                        <i-select v-model="formValidate.color" placeholder="请选择车身颜色">
                            <template v-for="(item,index) in colorArr">
                                <i-option :value="item">{{item}}</i-option>
                            </template>
                        </i-select>
                    </Form-item>
                    <Form-item label="车辆品牌" prop="brand">
                        <i-select v-model="formValidate.brand" placeholder="请选择车量品牌">
                            <template v-for="(item,index) in brandArr">
                                <i-option :value="item">{{item}}</i-option>
                            </template>
                        </i-select>
                    </Form-item>
                    <Form-item label="选择用车类型" prop="cartypeid">
                        <i-select v-model="formValidate.cartypeid" placeholder="请选择用车类型">
                            <template v-for="(item,index) in carTypeArr">
                                <i-option :value="item.Id">{{item.Title}}</i-option>
                            </template>
                        </i-select>
                    </Form-item>
                    <Form-item label="允许通行门区" prop="allowgates">
                        <i-select  placeholder="选择允许通行门区" multiple  :model.sync="formValidate.gates" filterable @on-change="checkChangeGate" >
                            <i-option  v-for="item in geteListArr" :value="item.Id">{{ item.Gatename }}</i-option>
                        </i-select>
                    </Form-item>
                    <Form-item label="行驶里程数" prop="drivedmiles">
                        <i-input v-model="formValidate.drivedmiles" type="number" placeholder="请输入行驶里程数"></i-input>
                    </Form-item>
                </div>
            </div>
            <div class="driver-block1">
                <p style="color: white;font-size: 15px;font-weight: bold;text-align: center;padding: 10px 0;background: #2196F3;">绑定驾驶员信息</p>
                <div style="padding:30px">
                    <Form-item label="驾驶员名字" prop="cusname">
                        <i-input v-model="formValidate.cusname" placeholder="请输入驾驶员姓名"></i-input>
                    </Form-item>
                    <Form-item label="驾驶员电话" prop="cusphone">
                        <i-input v-model="formValidate.cusphone" placeholder="请输入驾驶员电话"></i-input>
                    </Form-item>
                    <Form-item label="驾驶员单位" prop="cusunit">
                        <i-input v-model="formValidate.cusunit" placeholder="请输入驾驶员单位"></i-input>
                    </Form-item>
                    <Form-item label="驾驶员部门" prop="cusdepart">
                        <i-input v-model="formValidate.cusdepart" placeholder="请输入驾驶员部门"></i-input>
                    </Form-item>
                    <Form-item label="备注" prop="cusbak">
                        <i-input v-model="formValidate.cusbak" placeholder="请输入备注"></i-input>
                    </Form-item>
                </div>
            </div>
        </div>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" style="margin-top: 30px;display: block;text-align: center"
                      　type="primary">提交
            </i-button>
            <i-button @click="jumpPage('','CarPrivateList')" style="margin-left: 8px">返回</i-button>
        </Form-item>
    </i-form>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import baseUtil from '../../assets/utils/base-util';


    /**
     *  车牌号 platenum, 车辆卡编号 cardid，
     *  车辆自编号 carcode, 车辆车架号 carsn,
     *  车身颜色 color， 车辆品牌 brand
     *  参数: 行驶里程数 drivedmiles
     *  cusname，cusphone，cusunit，cusdepart，cusbak
     */


    export default {
        data() {
            return {
                formValidate: {
                    //添加字段
                    platenum: '',
                    cardid: '',
                    carcode: '',
                    carsn: '',
                    color: '',
                    brand: '',
                    drivedmiles: '',
                    cusname: '',
                    cusphone: '',
                    cusunit: '',
                    cusdepart: '',
                    cusbak: '',
                    gates:'',
                    cartypeid:'',

                },
                colorArr: ['红', '橙', '黄', '绿', '青'],
                brandArr: ['大众', '奔驰', '宝马', '红旗'],
                ruleValidate: {},
                //门区列表
                geteListArr: [],
                //车两类型
                carTypeArr:[],
            }
        },
        components: {},
        mounted: function () {
            // this.uploadList();
            this.getGateList();
            this.getCarTypeArr();
            this.getNextCards();

        },
        methods: {
            //跳转
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.addData(model);
                })
            },
            //获取一卡通
            getNextCards() {
                let that = this;
                let para = {};
                let params = that.$qs.stringify(para);
                // this.$Loading.star();
                apiUtil.get(that, apiUtil.urls.GetNextCards, params, function (res) {
                    // that.$Loading.finish();
                    // that.oneCard = res.Msg;
                    that.formValidate.cardid = res.Msg;

                    console.log('一卡通')
                });
            },
            //获取车类型
            getCarTypeArr: function () {
                let that = this;

                let para = {};
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.CarTypesList, params, function (res) {
                    that.$Loading.finish();
                    that.carTypeArr = res.Msg;
                });
            },
            //获取门区信息
            getGateList() {
                let that = this;

                let para = {};
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.GateServerList, para, function (res) {
                    that.$Loading.finish();
                    that.geteListArr = res.Msg;
                });

            },
            //选择门区
            checkChangeGate: function (data) {
                console.log('多选值:', data);
                let arr = Array.from(data);
                // this.formValidate.Gates =arr.join();
                this.formValidate.gates =arr;
                // console.log('checkChangeGate:', this.formValidate.Gates);
            },
            //添加
            addData: function (model) {
                let that = this;

                let params = that.$qs.stringify(model);
                this.$Loading.start();

                apiUtil.post(that, apiUtil.urls.AddCustomerCar, params, function (res) {
                    that.$Loading.finish();

                    that.$Modal.confirm({
                        title: '操作成功',
                        content: '请选择下一步操作',
                        okText: '继续添加',
                        cancelText: '返回列表',
                        onOk: () => {
                            that.$router.go(0);
                        },
                        onCancel: () => {
                            baseUtil.pageJump(that, '', 'CarPrivateList')
                        }
                    });

                });
            },

        }
    }
</script>
